package com.config;

import com.google.common.base.Predicate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author HuangSuip
 */
@EnableSwagger2
@Configuration
//@Profile("dev")
public class ApiDocumentConfig {

    @Bean
    //@Profile("dev")
    public static Docket docket() {

        Predicate<RequestHandler> handle = RequestHandlerSelectors.basePackage("com.controller");
        Predicate<RequestHandler> handle2 = RequestHandlerSelectors.basePackage("com.feng.controller");
        //java.util.function.Predicate<RequestHandler> or = handle2.or(handle);
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(getApiInfo())
            .select()
            //.apis(handle)
            .apis(handle)
            .paths(PathSelectors.any())
            .build();
    }

    private static ApiInfo getApiInfo() {
        return new ApiInfoBuilder()
            .title("Caiji HMS Web API")
            .termsOfServiceUrl("http://cjhms.ecaicn.com")
            .version("1.0")
            .build();
    }
}
